package com.xkcoding.orm.mybatis.plus.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xkcoding.orm.mybatis.plus.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * UserMapper
 * </p>
 *
 * @author andrew
 * @date Created in 2021-09-17 10:17
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from orm_user")
    List<HashMap> findUserRole();

    List<HashMap> selectAll();  //xml

    @Insert("INSERT INTO orm_user(name,password,salt,email,phone_number,status,create_time,last_login_time,last_update_time)" +
            " VALUES (#{name},#{password},#{salt},#{email}," +
            " #{phoneNumber}, #{status}, #{createTime},#{lastLoginTime}, #{lastUpdateTime})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void insertOneUser(User user);

    @Insert("<script>INSERT INTO orm_user(name,password,salt,email,phone_number,status,create_time,last_login_time,last_update_time)" +
            " VALUE <foreach collection='list' item='user' separator=',' > (#{user.name},#{user.password},#{user.salt},#{user.email}," +
            " #{user.phoneNumber}, #{user.status}, #{user.createTime},#{user.lastLoginTime}, #{user.lastUpdateTime}) </foreach></script> ")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void insertMoreUser(List<User> list);



}
